.TH std::char_traits::length,std::char_traits::length, 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::char_traits::length,std::char_traits::length, \- std::char_traits::length,std::char_traits::length,

.SH Synopsis
                            std::char_traits<char32_t>::length

   static std::size_t length( const char_type* s );  (constexpr since C++17)

   Returns the length of the character sequence pointed to by s, that is, the position
   of the terminating null character (char_type()).

   See CharTraits for the general requirements on character traits for X::length.

.SH Parameters

   s - pointer to a character sequence to return length of

.SH Return value

   The length of character sequence pointed to by s.

.SH Complexity

   Linear.

.SH Example


// Run this code

 #include <iomanip>
 #include <iostream>
 #include <string>

 void print(const char* str)
 {
     std::cout << std::quoted(str) << " has length = "
               << std::char_traits<char>::length(str) << '\\n';
 }

 int main()
 {
     print("foo");

     std::string s{"booo"};
     print(s.c_str());
 }

.SH Output:

 "foo" has length = 3
 "booo" has length = 4
